#ifndef _ARCH_PKG_H
#define _ARCH_PKG_H

#include <glib.h>
#include <glib-object.h>

G_BEGIN_DECLS 

//ret = alpm_pkg_vercmp(s1, s2);

//char *test_pkg_strs[] = { "virtualbox_bin-3.1.0-1-i686.pkg.tar.gz", "pyclewn-0.6-1-i686.pkg.tar.gz", "webqam-1.0.0-1-i686.pkg.tar.gz"};

//   #define DEFINE_MACRO(T_N, OBJECT_N, obj_n) \
//   #define G_TYPE_##T_N## (g_##obj_n##_get_type()) \
//   #define G_ARCH_PKG(obj)     (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_##T_N, OBJECT_N)) \
//   #define G_IS_##T_N(obj)  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_##T_N)) \
//   #define G_##T_N##_CLASS(kclass) (G_TYPE_CHECK_CLASS_TYPE((kclass), G_TYPE_##T_N)) \
//   #define G_##T_N##_GET_CLASS(inst)  (G_TYPE_INSTANCE_GET_CLASS((inst), G_TYPE_##T_N, OBJECT_N##Class)) \

//#define DEF_PRIVATE(DF, TN, OBJECT_N) \
//#DF##define G_##T_N##_GET_PRIVATE(inst) G_TYPE_INSTANCE_GET_PRIVATE (inst, G_TYPE_##T_N, OBJECT_N##Private) 

//DEFINE_MACRO(ARCH_PKG, GArchPkg, arch_pkg)
//DEF_PRIVATE(#, ARCH_PKG, GArchPkg)

#define G_TYPE_ARCH_PKG     (g_arch_pkg_get_type())
#define G_ARCH_PKG(obj)     (G_TYPE_CHECK_INSTANCE_CAST ((obj), G_TYPE_ARCH_PKG, GArchPkg))
#define G_IS_ARCH_PKG(obj)  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), G_TYPE_ARCH_PKG))
#define G_ARCH_PKG_CLASS(kclass) (G_TYPE_CHECK_CLASS_TYPE((kclass), G_TYPE_ARCH_PKG))
#define G_ARCH_PKG_GET_CLASS(inst)  (G_TYPE_INSTANCE_GET_CLASS((inst), G_TYPE_ARCH_PKG, GArchPkgClass))
#define G_ARCH_PKG_GET_PRIVATE(inst) G_TYPE_INSTANCE_GET_PRIVATE (inst, G_TYPE_ARCH_PKG, GArchPkgPrivate)
//#define G_ARCH_PKG_GET_IFACE(obj)  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), G_TYPE_ARCH_PKG, GArchPkgIface))


typedef struct _GArchPkgPrivate GArchPkgPrivate;
typedef struct _GArchPkgClass   GArchPkgClass;


struct _GArchPkgClass {
    GObjectClass parent_class;
    void (*_g_reserved1) (void);
};

typedef struct _GArchPkg {
    GObject parent_instance;
    GArchPkgPrivate *priv;
}GArchPkg ;


extern GType       g_arch_pkg_get_type(void);
extern GArchPkg *  g_arch_pkg_new(void);
extern void g_arch_pkg_print_info(GArchPkg *arch_pkg);
extern gboolean g_arch_pkg_parse_by_str(GArchPkg *arch_pkg, const char *pkg_str);
extern void g_arch_pkg_delete_delete_file(GArchPkg *arch_pkg, const char *dir_name, gboolean b_unlink_en);





typedef enum {
   ARCH_TYPE_I686 = 0, 
   ARCH_TYPE_X86_64, 
   ARCH_TYPE_ANY, 
   ARCH_TYPE_NO_ARCH, 
}EArchType_t;

#define ARCH_NAME_MAX_LEN    16
typedef struct {
    char str_arch_name[ARCH_NAME_MAX_LEN];
    EArchType_t  arch_type;
}TArchMap_t;


extern const TArchMap_t g_arch_map_tbl[];

typedef struct _ArchPkg{
    char    *pkg_name;
    char    *pkg_ver;
    char    *pkg_relver;
    char    *pkg_arch_name;
    char    *pkg_suffx_name;
    char    *pkg_file_name;
    char    *pkg_full_ver;
    int     pkg_relver_num;
    gboolean b_pkg_avail;
    EArchType_t arch_type;
}TArchPkg_t ;//__attribute__((packed)) TArchPkg_t ;


extern void print_arch_pkg(TArchPkg_t *p_arch_pkg);
extern int parse_arch_pkg(TArchPkg_t *p_arch_pkg, const char *pkg_str);
extern void init_arch_pkg(TArchPkg_t *p_arch_pkg);
extern TArchPkg_t *arch_pkg_new(void);
extern void free_arch_pkg(TArchPkg_t *p_arch_pkg);

extern GList *scan_pkgs(char *dir);
extern void show_pkg(gpointer pkg_ptr, gpointer user_data);
extern void free_pkg(gpointer pkg_ptr, gpointer user_data);
extern void show_all_list_pkg(GList *list);
extern void free_all_list_pkg(GList *list);
extern int chk_is_arch_pkg_file(const char *p_file_name);
extern gint cmp_arch_pkg_name(gconstpointer  a, gconstpointer  b);
extern gint cmp_arch_pkg_full_ver(gconstpointer  a, gconstpointer  b);
extern GList *find_remove_pkgs(GList *pkg_list);
extern void free_same_pkg_list(gpointer list_data, gpointer user_data);
extern void free_scan_pkgs_list(GList *list);
extern void show_single_pkg_list_info(GList *list);
extern void show_single_pkg_list_filename(GList *list);
extern void delete_single_pkg_list_filename(GList *list, const char *dir_name, gboolean b_unlink_en);
extern void ShowRemovePkgListFileName(GList *list);
extern void DeleteRemovePkgListFileName(GList *list, const char *dir_name, gboolean b_unlink_en);
extern void ShowRemovePkgListInfo(GList *list);
extern GList *filter_single_pkg_list(GList *list, guint save_num);
extern GList *FilterRemovePkgList(GList *list, guint save_num);

G_END_DECLS

#endif
